package com.example.deepclonetest.myTest;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;

public class CloneTest {

    private static final Logger logger = LoggerFactory.getLogger(CloneTest.class);

    public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException {

        //默认深克隆
        Car car = new Car("奔驰", new Wheel("简特", 26));
        Car clone = (Car) car.deepCloneDefault();
        clone.wheel.name = "经济";
        clone.name = "宝马";
        logger.info(String.valueOf(car));
        logger.info(String.valueOf(clone));

        //序列化深克隆
        Car car2 = new Car("奔驰", new Wheel("简特", 26),1);
        Car deepClone = car2.deepCloneSerializable();
        deepClone.name = "宝马";
        deepClone.wheel.name = "经济";
        int a = car2.a;
        System.out.println(a+" clone.a: "+clone.a);
        logger.debug(String.valueOf(car2));
        logger.info(String.valueOf(clone));

        //浅克隆
        Car car3 = new Car("奔驰", new Wheel("简特", 26));
        Car lightClone = (Car) car3.clone();
        lightClone.name = "宝马";
        lightClone.wheel.name = "经济";
        logger.error(String.valueOf(car));
        logger.warn(String.valueOf(clone));

        HashMap<Integer, String> map = new HashMap<>(8);
        map.put(1, "one");
        String two = map.put(2, "two");
        System.out.println("two " + two);
        map.put(new Integer("3"), "three1");
        map.put(new Integer("3"), "three2");
        map.put(new Integer("3"), "three3");
        map.put(new Integer("3"), "three4");
        map.put(new Integer("3"), "three5");
        map.put(new Integer("3"), "three6");
        map.put(new Integer("3"), "three7");
        map.put(new Integer("3"), "three8");
        map.put(4, "four");
        map.put(5, "five");
        map.put(6, "six");
        map.put(7, "seven");
        map.get(1);
        new Thread(() -> map.put(8, "eight")).start();
        new Thread(() -> map.put(9, "eight")).start();
        new Thread(() -> {
            map.entrySet().forEach((entry) -> {
                System.out.println(entry.getKey());
                System.out.println(entry.getValue());
            });
        }).start();
        new Thread(() -> map.put(10, "eight")).start();

        Hashtable<Integer, String> integerStringHashtable = new Hashtable<>(10);
        HashMap<Integer, String> integerStringHashMap = new HashMap<>(map);
        for (int i = 1; i <= 5; i++) {
            System.out.println(-1 >> i);
        }
        System.out.println(-1 >> 1);
        Integer i = 2;
        int i1 = i.hashCode();
        int[] ints=new int[12];
        System.out.println(ints);
//        Hashtable
    }
}
